package tictactoe.GUI;

import tictactoe.multiplayer.TestServer;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import tictactoe.multiplayer.server.Server;

/**
 *
 * @author Home
 */
public class Main extends javax.swing.JFrame {

    /**
     *
     * @param args
     */
    public static void main(String args[]) {
        try {
            LookAndFeel laf = (LookAndFeel) Class.forName(UIManager.getSystemLookAndFeelClassName()).newInstance();
            UIManager.setLookAndFeel(laf);
        } catch (InstantiationException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        Main m = new Main();

        m.setLocationByPlatform(true);
        m.setLocale(Locale.US);
        m.setVisible(true);
    }

    /**
     *
     */
    public Main() {
        initComponents();
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        content = new javax.swing.JPanel();
        single = new javax.swing.JButton();
        multiLocal = new javax.swing.JButton();
        multiNet = new javax.swing.JButton();
        about = new javax.swing.JButton();
        quit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("tictactoe/GUI/texts"); // NOI18N
        setTitle(bundle.getString("title")); // NOI18N
        setResizable(false);

        content.setMaximumSize(new java.awt.Dimension(300, 200));
        content.setMinimumSize(new java.awt.Dimension(300, 200));
        content.setPreferredSize(new java.awt.Dimension(300, 200));
        content.setLayout(new java.awt.GridLayout(0, 1, 0, 5));

        single.setText(bundle.getString("startSingle")); // NOI18N
        single.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                singleActionPerformed(evt);
            }
        });
        content.add(single);

        multiLocal.setText(bundle.getString("startMultiLocal")); // NOI18N
        multiLocal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multiLocalActionPerformed(evt);
            }
        });
        content.add(multiLocal);

        multiNet.setText(bundle.getString("startMultiNet")); // NOI18N
        multiNet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multiNetActionPerformed(evt);
            }
        });
        content.add(multiNet);

        about.setText(bundle.getString("about")); // NOI18N
        about.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutActionPerformed(evt);
            }
        });
        content.add(about);

        quit.setText(bundle.getString("quit")); // NOI18N
        quit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitActionPerformed(evt);
            }
        });
        content.add(quit);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(content, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(content, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void singleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleActionPerformed
        //TODO: multiplayer over the internet
//        JOptionPane.showMessageDialog(this, "Одоогоор шийдэгдээгүй.");
        //TestServer aa = new TestServer();

        Server s =new Server();
        try {
            s.startServer();
            //testServer.setVisible(false);
            //testServer.setVisible(false);
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_singleActionPerformed

    private void multiLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiLocalActionPerformed
        JOptionPane.showMessageDialog(this, "Одоогоор шийдэгдээгүй.");
    }//GEN-LAST:event_multiLocalActionPerformed

    private void multiNetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiNetActionPerformed
        NewMultiplayer nm = new NewMultiplayer(this);
        nm.setLocation(getLocation());
        setVisible(false);
        nm.setVisible(true);
        setLocation(nm.getLocation());
        setVisible(true);
    }//GEN-LAST:event_multiNetActionPerformed

    private void aboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutActionPerformed
        //TODO: about
        JOptionPane.showMessageDialog(this, "Одоогоор шийдэгдээгүй.");
    }//GEN-LAST:event_aboutActionPerformed

    private void quitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitActionPerformed
        dispose();
    }//GEN-LAST:event_quitActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton about;
    private javax.swing.JPanel content;
    private javax.swing.JButton multiLocal;
    private javax.swing.JButton multiNet;
    private javax.swing.JButton quit;
    private javax.swing.JButton single;
    // End of variables declaration//GEN-END:variables
}
